Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Allow NgModelController to be copied #15836

Merged
merged 2 commits into from
Mar 28, 2017
Merged

Allow NgModelController to be copied #15836

merged 2 commits into from
Mar 28, 2017

Conversation

jbedard
Copy link
Collaborator

@jbedard jbedard commented Mar 21, 2017

What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
fix

What is the current behavior? (You can also link to an open issue here)
copy throws when copying a NgModelController instance. This will occur when deep watching such as when doing <e ref="[myNgModel]"> (#15833)

What is the new behavior (if this is a feature change)?
The internal NgModelController $$scope is hidden

Does this PR introduce a breaking change?
no, unless someone is doing something crazy that depends on $$scope being enumerable?

Please check if the PR fulfills these requirements

Other information:
I've split the commit up into 3. I think the refactor + (modified) test should go into 1.7. I don't think the actual fix should go into 1.7. The specific test case (watched a literal containing an ng-model) will no longer fail in 1.7. If we want to prevent other cases like manually deep-watching or manually copying an ng-model I think we should do it differently in 1.7...

this.$$scope = $scope;
//https://github.com/angular/angular.js/issues/15833
//Prevent `$$scope` from being iterated over by `copy` when NgModelController is deep watched
//TODO: remove this or do not merge into 1.7
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't merge into 1.7, so you can remove this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've dropped this line.

expect(componentScope.undi).toBeDefined();
//TODO: the `.not` should be removed in 1.7 due to
//https://github.com/angular/angular.js/commit/fd4f0111188b62773b99ab6eab38b4d2b5d8d727
expect(componentScope.undi).not.toBe($rootScope.f.i);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this line is redundant (it doesn't add anything to the test). Could we use toEqual() (which would work the same in 1.6.x/1.7.x)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we do keep this line I'd prefer .toBe in 1.7 to verify that it is the exact same instance, so I figured .not.toBe would be better for now, if we keep this line.

Only the $compile line is actually necessary to reproduce the issue. Maybe I should drop everything else?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MY reasoning is that there are other tests that verify the toBe() behavior (for 1.7), so I wouldn't be too worried about it here. But dropping everything not necessary for the test works for me too.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok I've dropped everything except the verification that the binding actually got set...

@Narretz
Copy link
Contributor

Narretz commented Mar 27, 2017

LGTM, please squash and merge

@@ -5858,6 +5858,29 @@ describe('$compile', function() {
expect(componentScope.owRef).toEqual({name: 'lucas', item: {name: 'martin'}});
}));

//https://github.com/angular/angular.js/issues/15833
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we start every comment with a space?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why? order?

@@ -281,7 +281,9 @@ function NgModelController($scope, $exceptionHandler, $attr, $element, $parse, $

this.$$currentValidationRunId = 0;

this.$$scope = $scope;
//https://github.com/angular/angular.js/issues/15833
//Prevent `$$scope` from being iterated over by `copy` when NgModelController is deep watched
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have spaces after // in above two lines?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, my friend ...

@jbedard jbedard merged commit e1f8a6e into angular:v1.6.x Mar 28, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants